package com.zide.link.service.impl;

import java.util.Arrays;
import java.util.List;

import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.zide.common.core.domain.PageResult;
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.util.ArrayUtil;
import com.zide.common.core.vo.CommonParamIdVO;
import com.zide.common.utils.DateUtils;
import com.zide.link.domain.po.LinkSearch;
import com.zide.link.domain.vo.result.LinkSearchResultVO;
import com.zide.link.domain.vo.save.LinkSearchSaveVO;
import com.zide.link.domain.vo.search.LinkSearchSearchVO;
import com.zide.link.mapper.LinkSearchMapper;
import com.zide.link.service.ILinkSearchService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * 搜索引擎Service业务层处理
 * 
 * @author zide
 * @date 2024-05-10
 */
@Slf4j
@Service
public class LinkSearchServiceImpl implements ILinkSearchService {
    @Autowired
    private LinkSearchMapper linkSearchMapper;

    /**
     * 查询搜索引擎列表
     */
    @Override
    public List<LinkSearchResultVO> searchLinkList(LinkSearchSearchVO searchVO) {
        LambdaQueryWrapper<LinkSearch> wrapper = new LambdaQueryWrapper<>();
        if(ObjectUtil.isNotNull(searchVO.getStatus())) {
            wrapper.eq(LinkSearch::getStatus,searchVO.getStatus());
        }
        List<LinkSearch> dbPageResult = linkSearchMapper.selectList(wrapper);
        List<LinkSearchResultVO> resultList = BeanUtil.copyToList(dbPageResult,LinkSearchResultVO.class);
        return resultList;
    }

    /**
     * 查询搜索引擎详情
     */
    @Override
    public LinkSearchResultVO selectLinkSearchById(Long id) {
            LinkSearch dbInfo = linkSearchMapper.selectById(id);
            LinkSearchResultVO result = BeanUtil.copyProperties(dbInfo,LinkSearchResultVO.class);
        return result;
    }

    /**
     * 新增搜索引擎
     */
    @Override
    public int saveLinkSearch(LinkSearchSaveVO saveVO) {
        LinkSearch insertBean = BeanUtil.copyProperties(saveVO,LinkSearch.class);
        return linkSearchMapper.insert(insertBean);
    }

    /**
     * 修改搜索引擎
     */
    @Override
    public int updateLinkSearch(LinkSearchSaveVO saveVO) {
        LinkSearch updateBean = BeanUtil.copyProperties(saveVO,LinkSearch.class);
        return linkSearchMapper.updateById(updateBean);
    }

    /**
     * 批量删除搜索引擎
     */
    @Override
    public int removeLinkSearchByIds(CommonParamIdVO idVO) {
        if(ArrayUtil.isNotEmpty(idVO.getIds())) {
            return linkSearchMapper.deleteBatchIds(Arrays.asList(idVO.getIds()));
        }else {
            return linkSearchMapper.deleteById(idVO.getId());
        }

    }

    @Override
    public int updateStatus(LinkSearchSaveVO saveVO) {
        LinkSearch updateBean = BeanUtil.copyProperties(saveVO,LinkSearch.class);
        return linkSearchMapper.updateById(updateBean);
    }
}
